package DB_operation

import "golang.org/x/crypto/bcrypt"

// 注册-新增
func (u *UserInfo) Create() error {
	return DB.Self.Create(&u).Error
}

// 密码加密
func (u *UserInfo) Encrypt() (err error) {
	u.UserPassword, err = Encrypt(u.UserPassword)
	return
}

// bcrypt  加密文本信息
func Encrypt(source string) (string, error) {
	hashedBytes, err := bcrypt.GenerateFromPassword([]byte(source), bcrypt.DefaultCost)
	return string(hashedBytes), err
}
